import Cookies from "js-cookie";

const TokenKey: string = "LOGIN_TOKEN_STRING";
const LoginInfoKey: string = "LOGIN_INFO_OBJECT";

export function getToken(): string | undefined {
    return Cookies.get(TokenKey);
}

export function setToken(token: string): string | undefined {
    return Cookies.set(TokenKey, token);
}

export function removeToken() {
    return Cookies.remove(TokenKey);
}

export function getLoginInfo(): any {
    return Cookies.get(LoginInfoKey);
}

export function setLoginInfo(LoginInfo: string): any {
    return Cookies.set(LoginInfoKey, LoginInfo);
}

export function removeLoginInfo() {
    return Cookies.remove(LoginInfoKey);
}

export function systemLogout() {
    removeToken()
    removeLoginInfo()
    localStorage.removeItem('lastRoute')
    localStorage.removeItem('basicsPagesList')
    localStorage.removeItem('controlPagesList')
    // 使用 reload 时，不需要调用 resetRoute() 重置路由
    window.location.reload() // 页面刷新
}
